package com.yueqian;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import lombok.extern.slf4j.Slf4j;

@SpringBootApplication
@Slf4j
public class SpringBoot3Application {

	public static void main(String[] args) {
		ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringBoot3Application.class, args);
		Environment env = applicationContext.getEnvironment();
		logApplicationStartup(env);
	}

	private static void logApplicationStartup(Environment env) {
		String protocol = "http";
		if (env.getProperty("server.ssl.key-store") != null) {
			protocol = "https";
		}
		String serverPort = env.getProperty("server.port");
		String contextPath = env.getProperty("server.servlet.context-path");
		if (!StringUtils.hasText(contextPath)) {
			contextPath = "/doc.html";
		} else {
			contextPath = contextPath + "/doc.html";
		}
		String hostAddress = "localhost";
		try {
			hostAddress = InetAddress.getLocalHost().getHostAddress();
		} catch (UnknownHostException e) {
			log.warn("The host name could not be determined, using `localhost` as fallback");
		}
//		log.info("应用程序“{}”正在运行中......",env.getProperty("spring.application.name"));
//		log.info("接口文档访问 URL:");
//		log.info("应用程序“{}”正在运行中......",env.getProperty("spring.application.name"));
//
//
//		log.info("接口文档访问 URL:");

//		log.info("
//						----------------------------------------------------------
//						应用程序“{}”正在运行中......
//						接口文档访问 URL:
//						本地: \t{}://localhost:{}{}
//						外部: \t{}://{}:{}{}
//						配置文件: \t{}
//						----------------------------------------------------------
//						",
//				env.getProperty("spring.application.name"),
//				protocol,
//				serverPort,
//				contextPath,
//				protocol,
//				hostAddress,
//				serverPort,
//				contextPath,
//				env.getActiveProfiles()));
	}


}
